#include "mainscene.h"
#include "ui_mainscene.h"
#include "QPainter"
#include "mypushbutton.h"
#include "chooselevelscene.h"
#include "QTimer"
#include "QSound"
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
     this->setFixedSize(320,588);
    this->setWindowTitle("吉哥带你翻金币");
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));

    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });
    myPushButton *StartBtn=new myPushButton(":/res/MenuSceneStartButton.png");
    StartBtn->setParent(this);
    StartBtn->move(this->width()*0.5-StartBtn->width()*0.5,this->height()*0.7);

    //设置音效
    QSound *startSound=new QSound(":/res/TapButtonSound.wav",this);
    QSound *backSound=new QSound(":/res/BackButtonSound.wav",this);

    ChooseLevelScene *choosescene=new ChooseLevelScene();
    connect(StartBtn,&QPushButton::clicked,[=](){
        startSound->play();
        //移动，利用动态对象
        StartBtn->zoom1();
        StartBtn->zoom2();
        //利用定时器封装函数阻塞,并且实现对应类似槽函数，类似延时
        QTimer::singleShot(400,this,[=](){
            //设置大小为一样
            choosescene->setGeometry(this->geometry());
            this->hide();
            choosescene->show();
        });
    });
    connect(choosescene,&ChooseLevelScene::chooseScenceBack,this,[=](){
        this->setGeometry(choosescene->geometry());
        backSound->play();
        this->show();
        choosescene->hide();
    });



}

void MainScene::paintEvent(QPaintEvent*){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/res/Title.png");
    //可以通过绘图设备来设置图片的大小
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);
}


MainScene::~MainScene()
{
    delete ui;
}

